export default class DCMStudy {
	constructor(args) {
		this.seriesList = []; // 序列列表
		this.patientId = "";
		this.patientName = "";
		this.studyAge = "";
		this.birthday = "";
		this.gender = "";
		this.studyId = "";
		this.studyInsUid = "";
		this.radiId = "";
		this.studyDate = "";
		this.modality = "";
		this.isMain = false;

		if (args) {
			this.patientId = args.patientId;
			this.patientName = args.patientName;
			this.studyAge = args.studyAge;
			this.birthday = args.birthday;
			this.gender = args.gender;
			this.studyId = args.studyId;
			this.studyInsUid = args.studyInsUid;
			this.radiId = args.radiId;
			this.studyDate = args.studyDate;
			this.modality = args.modality;
			this.isMain = args.isMain;
		}
	}

	AddSeries(series, sort = true) {
		if (!series) return;
		const existSer = this.seriesList.find(
			item => item.seriesInsUid === series.seriesInsUid
		);
		if (!existSer) {
			series.study = this;
			this.seriesList.push(series);
			if (sort) {
				this.Sort();
			}
		}
	}

	FindSeries(seriesInsUid) {
		return this.seriesList.find(item => item.seriesInsUid === seriesInsUid);
	}

	Sort(bAsc = true) {
		if (this.orgsertime) {
			// 存在原始序列时间, 按序列时间排序
			if (config.showlog) console.log("按序列时间排序");
			this.seriesList.sort(function (a, b) {
				const dateStrA = a.seriesDate + "T" + a.seriesTime + "Z";
				const dateStrB = b.seriesDate + "T" + b.seriesTime + "Z";
				const s1 = Date.parse(dateStrA);
				const s2 = Date.parse(dateStrB);
				return bAsc ? s1 - s2 : s2 - s1;
			});
		} else {
			// 不存在原始序列时间, 按序列号排序
			if (config.showlog) console.log("按序列号排序");
			this.seriesList.sort(function (a, b) {
				// 按序列号排序
				const s1 = parseInt(a.seriesNumber);
				const s2 = parseInt(b.seriesNumber);
				return bAsc ? s1 - s2 : s2 - s1;
			});
		}
	}
}
